package sicnu.cs.aps.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import sicnu.cs.aps.domain.dto.CollegeInfoDto;
import sicnu.cs.aps.domain.entity.CollegeInfo;
import sicnu.cs.aps.domain.entity.Major;
import sicnu.cs.aps.domain.form.QueryForm;
import sicnu.cs.aps.mapper.CollegeInfoMapper;
import sicnu.cs.aps.mapper.MajorInfoMapper;
import sicnu.cs.aps.service.ICollegeInfoService;

import java.util.ArrayList;
import java.util.List;

/**
 * description 学院信息service实现
 *
 * @author chenhetao
 * @version 1.0
 * @className ICollegeInfoService
 * @packageName sicnu.cs.aps.service
 * @date 2022/5/26 18:47
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class CollegeInfoServiceImpl implements ICollegeInfoService {

    private final CollegeInfoMapper collegeInfoMapper;
    private final MajorInfoMapper majorInfoMapper;

    /**
     * 通过数据库查找Excel需要的kv字段保存映射
     *
     * @return 对应的kv字符串
     */

    @Override
    public String getKv() {
        return null;
    }

    @Override
    public PageInfo<CollegeInfoDto> getCollegeInfoByName(QueryForm queryForm) {
        PageHelper.startPage(queryForm.getPageNum(), queryForm.getPageSize());
        List<CollegeInfoDto> collegeInfoForms = collegeInfoMapper.selectCollegeInfoByName(queryForm.getKeyword().trim());
        PageInfo<CollegeInfoDto> collegeInfoFormPageInfo = new PageInfo<>(collegeInfoForms);
        return collegeInfoFormPageInfo;
    }

    @Override
    public List<CollegeInfo> getCollegeInfoList() {
        return collegeInfoMapper.selectIDAndName();
    }

    @Override
    public List<CollegeInfoDto> getCollegeAndMajorInfoList() {
        List<CollegeInfoDto> collegeInfoDtoList = collegeInfoMapper.selectAllCollegeIdAndName();
//        List<Major> majorList = majorInfoMapper.selectAllMajor();
//        for (CollegeInfoDto collegeInfoDto : collegeInfoDtoList) {
//            List<Major> collegeInfoDtoMajorList = new ArrayList<>();
//            for (Major major : majorList) {
//                if (major.getCollegeId().equals(collegeInfoDto.getId())) {
//                    collegeInfoDtoMajorList.add(major);
//                }
//            }
//            collegeInfoDto.setMajorList(collegeInfoDtoMajorList);
//        }
        return collegeInfoDtoList;
    }

    @Override
    public List<CollegeInfoDto> getCollegeAndMajorInfo() {
        return collegeInfoMapper.selectCollegeInfoAndMajor();
    }


}
